package com.zhangsan.seionor1.week3.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.HandshakeInterceptor;

@Configuration
@EnableWebSocket
public class SocketConfig   implements WebSocketConfigurer {
	
	@Autowired
	HandshakeInterceptor myInterceptor;
	 
        @Override
        public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
            System.out.println("....注册......");
            //前台 可以使用websocket环境
          /* registry.addHandler(myHandler(),"/websocket").
           setAllowedOrigins("*").addInterceptors(this.myInterceptor);*/
           
           registry.addHandler(myHandler(), "/websocket") .setAllowedOrigins("*").addInterceptors(myInterceptor);
 
        } 
        // websocket 处理类
        @Bean
        public WebSocketHandler myHandler(){
            return new MyHandler();
        }
	 
	 
	}
